package br.ucb.GtTunningLog.client;

import com.google.gwt.user.client.ui.HTML;

/**
 * 
 * @author eduardo
 * Classe que abstrai a idéia de um post do site
 */
public class Post extends HTML{
	
	/**
	 * 
	 */
	private String title;
	private String message;
	private String submessage;
	private String owner;
	
	
	
	public Post(String title, String formatedMessage, String owner, String subpost){
		super("<div class=\"post\">" 
				+ "<h1 class=\"title\"><a href=\"#\">" + title + "</a></h1>"
				+ "<p class=\"meta\">Postado por <a href=\"#\">" + owner + "</a>em 28 de Maio de 2008"
				+ "&nbsp;&bull;&nbsp; <a href=\"#\" class=\"comments\">Comments (64)</a> &nbsp;&bull;&nbsp; <a href=\"#\" class=\"permalink\">Artigo Completo</a></p>"
				+ "<div class=\"entry\">"
				+ "<p>" + formatedMessage + "</p>"
				+ "<p>" + subpost + "</p>");
	}
	
	public String getString(){
		return this.getHTML();
	}
	
	public String getMessage() {
		return message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}
	
	public String getSubmessage() {
		return submessage;
	}
	
	public void setSubmessage(String submessage) {
		this.submessage = submessage;
	}
	
	public String getOwner() {
		return owner;
	}
	
	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	
	public String getTitle() {
		return title;
	}

	
	public void setTitle(String title) {
		this.title = title;
	}

	public static HTML createNewPost(String title, String formatedMessage, String owner, String subpost){
		
		String htmlHomeBody = "<div class=\"post\">" 
			+ "<h1 class=\"title\"><a href=\"#\">" + title + "</a></h1>"
			+ "<p class=\"meta\">Postado por <a href=\"#\">" + owner + "</a>em 28 de Maio de 2008"
			+ "&nbsp;&bull;&nbsp; <a href=\"#\" class=\"comments\">Comments (64)</a> &nbsp;&bull;&nbsp; <a href=\"#\" class=\"permalink\">Artigo Completo</a></p>"
			+ "<div class=\"entry\">"
			+ "<p>" + formatedMessage + "</p>";
			if(!"".equals(subpost) && subpost != ""){
				htmlHomeBody += "<p>" + subpost + "</p>";
			}
			
			htmlHomeBody += "</div>"
			+ "</div>";
		
		return new HTML(htmlHomeBody);
	}
	
	public HTML getHTMLPost(){
		return Post.createNewPost(this.title, this.message, this.owner, 
				this.submessage);
	}
}
